<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card :bordered="false">
      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
        :export-config="{ use: true,select: '创新工作室',all: '创新工作室'}"
      >
        <template
          slot="prefix"
          slot-scope="ref"
        >
          <a-button
            v-btn-permission="'lu_008_add_01'"
            type="primary"
            icon="plus"
            @click="$nav('add')"
          >
            新增
          </a-button>
          <ExcelImportButton
            v-btn-permission="'lu_008_imp_05'"
            icon="import"
            @handleSubmit="handleImport"
          >
            导入
          </ExcelImportButton>
          <export-mould
            style="margin-left: 5px"
            template-code="创新工作室模板.xlsx"
            icon="cloud-download"
          />
        </template>
        <span
          slot="index"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="createTime"
          slot-scope="text, record, index"
        >
          {{ record.createTime|dateFormat('D') }}
        </template>
        <template
          slot="operation"
          slot-scope="text, record, index"
        >
          <MoreButton>
            <a
              v-btn-permission="'lu_008_loo_04'"
              @click="$nav('add',{id:record.id,detail:1})"
            >查看</a>
            <a
              v-btn-permission="'lu_008_edi_02'"
              @click="$nav('add',{id:record.id})"
            >编辑</a>
            <a
              v-if="record.auditStatus !== 'PAST'"
              v-btn-permission="'lu_008_del_03'"
              @click="handleDel(record.id)"
            >删除</a>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import yiShiSanSaiApi from '@/api/union/yiShiSanSai'
import SelectCompanyAndSubCompany from '@/components/Select/SelectCompanyAndSubCompany'
import ExportMould from '@/components/ExportMould'

export default {
    name:'a'+Date.now(),

    components: {
        ExportMould
    },
    data() {
        return {
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    width: 70,
                    scopedSlots: { customRender: 'index' }
                }, {
                    title: '工作室名称',
                    dataIndex: 'studioName',
                    width: 150
                },
                {
                    title: '单位',
                    dataIndex: 'depName',
                    width: 150
                },
                {
                    title: '创建时间',
                    dataIndex: 'createTime',
                    scopedSlots: { customRender: 'createTime' },
                    width: 150
                },
                {
                    title: '团队人数',
                    dataIndex: 'teamNum',
                    width: 120
                },
                {
                    title: '成果数',
                    dataIndex: 'resultsNum',
                    width: 150
                },
                {
                    title: '领军人物',
                    dataIndex: 'leader',
                    width: 150
                },
                {
                    title: '领军人物获得的最高荣誉',
                    dataIndex: 'topLeader',
                    width: 180
                },
                {
                    title: '操作',
                    width: 200,
                    fixed: 'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            searchArr: [
                // 搜索框
                {
                    name: '工作室名称',
                    type: 'input',
                    value: 'studioName'
                },
                {
                    name: '单位',
                    valueKey: 'depId',
                    type: SelectCompanyAndSubCompany
                },
                {
                    name: '创建时间',
                    type: 'dateRangeFormatx',
                    value: 'createTime'
                },
                {
                    name: '领军人物',
                    type: 'input',
                    value: 'riskName'
                }
            ],
            loadData: (params) => {
                console.log(yiShiSanSaiApi.getPageStudio(Object.assign(params, { query: this.queryParam })),1)
                return yiShiSanSaiApi.getPageStudio(Object.assign(params, { query: this.queryParam }))
            },
            queryParam: {}
        }
    },
    methods: {
        async handleImport(e) {
            let columns = [
                { title: '工作室名称', dataIndex: 'studioName' },
                { title: '工作室地址', dataIndex: 'studioAddress' },
                { title: '所在单位', dataIndex: 'depName' },
                { title: '创建时间', dataIndex: 'createTime' },
                { title: '创新工作室级别', dataIndex: 'studioLevel' },
                { title: '创新工作室类型', dataIndex: 'studioType' },
                { title: '场地大小（㎡）', dataIndex: 'siteSize' },
                { title: '带头人姓名', dataIndex: 'name' },
                { title: '带头人电话号码', dataIndex: 'phone' },
                { title: '带头人最高荣誉', dataIndex: 'topHonor' }
            ]
            let newTable = []
            this.$console(e)
            e.map(row => {
                let temp = {}
                for (const rowKey in row) {
                    let column = columns.find(columnRow => columnRow.title === rowKey)
                    if (column) {
                        let dataIndex = column.dataIndex
                        temp[dataIndex] = row[rowKey]
                    }
                }
                if (temp.createTime) {
                    temp.createTime = new Date(temp.createTime).valueOf()
                }
                newTable.push(temp)
            })
            this.$console(newTable)


            this.loading = true
            let res = await yiShiSanSaiApi.insertStudioList(newTable)
            this.loading = false
            this.search()
            // this.$emit('refresh')
            // this.$notification.open({ message: '提示', duration: null, description: () => <pre>{res.message}</pre> })
            // console.log(newTable)
        },
        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleDel(id) {
            this.$delList3(yiShiSanSaiApi.deleteByPrimaryKey, () => {
                this.search()
            }, { id })
        }
    }
}
</script>
